from db.simple.simple_search import search
from db.common.db_map import update_db_map
from db.history import history, remember_search
from db.db_config import config_setting
from common.handle import Handle
from albertv0 import *


class Main(Handle):
    @classmethod
    def handle_query(cls, query_model):
        query_str = query_model.query_str
        if query_str == 'update':
            update_db_map()
            return {
                'text': '更新成功',
                'completion': 'db ',
            }
        if query_str == '-h':
            return history()
            pass
        if len(query_str) >= 6 and query_str[0:6] == 'config':
            return config_setting(query_model.add_index())
            pass
        return search(query_str)
        pass

    @classmethod
    def before_query(cls, query_model):
        # 记录查询
        remember_search(query_model)
        pass
    pass
